package com.quick.develop.form.controller;

import com.quick.develop.framework.common.page.PageResult;
import com.quick.develop.framework.common.utils.Result;
import com.quick.develop.form.entity.GenDynamicFormGroupEntity;
import com.quick.develop.form.query.GenDynamicFormGroupQuery;
import com.quick.develop.form.vo.GenDynamicFormGroupVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import com.quick.develop.form.convert.GenDynamicFormGroupConvert;
import com.quick.develop.form.service.GenDynamicFormGroupService;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 表单组
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2023-09-30
 */
@RestController
@RequestMapping("maku-generator/gen_dynamic_form_group")
@Tag(name = "表单组")
@AllArgsConstructor
public class GenDynamicFormGroupController {
    private final GenDynamicFormGroupService genDynamicFormGroupService;

    @GetMapping("page")
    @Operation(summary = "分页")
    public Result<PageResult<GenDynamicFormGroupVO>> page(GenDynamicFormGroupQuery query) {
        PageResult<GenDynamicFormGroupVO> page = genDynamicFormGroupService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    public Result<GenDynamicFormGroupVO> get(@PathVariable("id") Long id) {
        GenDynamicFormGroupEntity entity = genDynamicFormGroupService.getById(id);

        return Result.ok(GenDynamicFormGroupConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    public Result<String> save(@RequestBody GenDynamicFormGroupVO vo) {
        genDynamicFormGroupService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    public Result<String> update(@RequestBody @Valid GenDynamicFormGroupVO vo) {
        genDynamicFormGroupService.update(vo);

        return Result.ok();
    }

    @DeleteMapping("{ids}")
    @Operation(summary = "删除")
    public Result<String> delete(@PathVariable(value = "ids") List<Long> idList) {
        genDynamicFormGroupService.delete(idList);

        return Result.ok();
    }
}